package jfox.platform.aaa.bo;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import jfox.platform.aaa.dao.RoleDAO;
import jfox.platform.aaa.entity.Role;
import jfox.platform.aaa.entity.User;
import jfox.platform.infrastructure.DataAccessObject;
import jfox.platform.infrastructure.EntityNotExistedException;
import jfox.platform.infrastructure.SuperBO;

/**
 * 
 * @author <a href="mailto:thaiguo@gmail.com">Taiguo Zhang</a>
 *
 */

@Stateless
@Local
public class RoleBOBean extends SuperBO implements RoleBO {
	
	@EJB
	RoleDAO roleDAO;

	@Override
	public DataAccessObject getDataAccessObject() {
		
		return roleDAO;
	}

	public int deleteRole(long roleId) {
		
        Role role = roleDAO.getRoleById(roleId);        
        if(role == null){
            throw new EntityNotExistedException(Role.class, roleId);
        }
        // 判断 User 是否被引用
        checkEntityReferenced(role);
		return roleDAO.deleteRole(roleId);
	}

	public List<Role> getAllRoles() {
		return roleDAO.getAllRoles();
	}

	public Role getRoleById(long id) {
		return roleDAO.getRoleById(id);
	}

	public void newRole(Role role) {
		roleDAO.insertRole(role);
	}

	public int updateRole(Role role) {
		return roleDAO.updateRole(role);
	}

}
